<template>
    <div id="index" >
      <el-form >
      <el-form-item label="用户名">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="loginForm.password"></el-input>
      </el-form-item>
      <el-button @click="Login()">登录</el-button>
      </el-form>
    </div>
  </template>
  
  <script>
  import {useUser} from '@/store/modules/user';
  import {mapState,mapActions} from 'pinia';

  export default {
    
    data() {
      return {
        loginForm:{
          username: '',
        password: ''
        },
        user:{}
      };
    },
    methods:{
      ...mapActions(useUser,["doLogin"]),
      Login(){
      this.doLogin(this.loginForm).then(res => {
        localStorage.setItem("user", JSON.stringify(res.data));
        this.$router.replace("/hw2");
      })
    },
    }
  };
  </script>
  
  <style>
  </style>
  